#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
系统启动脚本
System Startup Script for AI Content Reliability Detection System
"""

import os
import sys
import argparse
from datetime import datetime

def main():
    """主启动函数"""
    parser = argparse.ArgumentParser(description='AI内容可靠性检测系统')
    parser.add_argument('--mode', choices=['web', 'cli', 'test'], default='web',
                       help='运行模式: web(Web界面), cli(命令行), test(测试)')
    parser.add_argument('--port', type=int, default=5000, help='Web服务器端口')
    parser.add_argument('--host', default='0.0.0.0', help='Web服务器主机')
    parser.add_argument('--debug', action='store_true', help='启用调试模式')
    
    args = parser.parse_args()
    
    print("=== AI内容可靠性检测系统 ===")
    print(f"启动时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
    print(f"运行模式: {args.mode}")
    
    if args.mode == 'web':
        print("启动Web界面...")
        print(f"访问地址: http://localhost:{args.port}")
        print("演示页面: http://localhost:{args.port}/demo")
        
        try:
            from web_interface import app
            app.run(debug=args.debug, host=args.host, port=args.port)
        except ImportError as e:
            print(f"导入Web界面模块失败: {e}")
            print("请确保已安装Flask: pip install flask")
            return 1
        except Exception as e:
            print(f"启动Web服务器失败: {e}")
            return 1
    
    elif args.mode == 'cli':
        print("启动命令行界面...")
        try:
            from ai_content_detector import main as cli_main
            cli_main()
        except Exception as e:
            print(f"启动命令行界面失败: {e}")
            return 1
    
    elif args.mode == 'test':
        print("运行系统测试...")
        try:
            from test_system import main as test_main
            success = test_main()
            return 0 if success else 1
        except Exception as e:
            print(f"运行测试失败: {e}")
            return 1
    
    return 0

if __name__ == "__main__":
    sys.exit(main()) 